import java.util.Scanner;

public class code3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str1 = sc.next();
        String str2 = sc.next();
        String[] str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = sc.next();
        }

        int fast = 1;
        int slow = 0;
        int ret = Integer.MAX_VALUE;
        for (; slow < n; slow++) {
            for (; fast < n;fast++) {
                if((str[slow].equals(str1)&&str[fast].equals(str2))||(str[slow].equals(str2)&&str[fast].equals(str1))){
                    ret = Math.max(Math.abs(fast-slow),ret);
                }
            }
        }
        System.out.println(ret);
    }
}
